Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix staticcheck failures for pkg/proxy/... #81886

Merged
merged 1 commit into from Dec 24, 2019

Conversation

praseodym
Copy link
Contributor

@praseodym praseodym commented Aug 24, 2019

What type of PR is this?

/kind cleanup
/priority important-longterm
/sig network

What this PR does / why we need it:

Cleanup the pkg/proxy/... issues identified by staticcheck in #81189:

pkg/proxy/healthcheck/proxier_health.go:55:2: field port is unused (U1000)
pkg/proxy/healthcheck/proxier_health.go:162:20: printf-style function with dynamic format string and no further arguments should use print-style function instead (SA1006)
pkg/proxy/healthcheck/service_health.go:166:20: printf-style function with dynamic format string and no further arguments should use print-style function instead (SA1006)
pkg/proxy/iptables/proxier.go:737:2: this value of args is never used (SA4006)
pkg/proxy/iptables/proxier.go:737:15: this result of append is never used, except maybe in other appends (SA4010)
pkg/proxy/iptables/proxier.go:1287:28: this result of append is never used, except maybe in other appends (SA4010)
pkg/proxy/userspace/proxysocket.go:293:3: this value of n is never used (SA4006)
pkg/proxy/winkernel/metrics.go:74:6: func sinceInMicroseconds is unused (U1000)
pkg/proxy/winkernel/metrics.go:79:6: func sinceInSeconds is unused (U1000)
pkg/proxy/winuserspace/proxier.go:94:2: field portMapMutex is unused (U1000)
pkg/proxy/winuserspace/proxier.go:118:2: field owner is unused (U1000)
pkg/proxy/winuserspace/proxier.go:119:2: field socket is unused (U1000)
pkg/proxy/winuserspace/proxysocket.go:620:4: this value of n is never used (SA4006)

Which issue(s) this PR fixes:

#36858, #81657

Special notes for your reviewer:

I'm not sure about the removal of unused fields in pkg/proxy/winuserspace/proxier.go, hopefully CI will catch any issues that I missed (I couldn't figure out how to do a cross build for only Windows).

Also, this PR overlaps with PR #81563 because that problem was caught by staticcheck as well. I'm happy to rebase once that PR is merged.

Does this PR introduce a user-facing change?:

NONE

@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. priority/important-longterm Important over the long term, but may not be staffed and/or may need multiple releases to complete. sig/network Categorizes an issue or PR as relevant to SIG Network. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Aug 24, 2019
@k8s-ci-robot
Copy link
Contributor

Hi @praseodym. Thanks for your PR.

I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@praseodym
Copy link
Contributor Author

/assign @lavalamp

@cmluciano
Copy link

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Aug 24, 2019
@praseodym
Copy link
Contributor Author

/retest

@praseodym praseodym force-pushed the fix-staticcheck-pkg/proxy branch 2 times, most recently from 15112b7 to 0973b8a Compare September 20, 2019 14:30
@praseodym
Copy link
Contributor Author

/retest

@vllry
Copy link
Contributor

vllry commented Sep 22, 2019

/assign

pkg/proxy/healthcheck/healthcheck.go Outdated Show resolved Hide resolved
pkg/proxy/healthcheck/healthcheck.go Outdated Show resolved Hide resolved
@praseodym praseodym force-pushed the fix-staticcheck-pkg/proxy branch 2 times, most recently from 2b8a014 to 02bea71 Compare September 22, 2019 12:04
// Not printing these comments, can reduce size of iptables (in case of large
// number of endpoints) even by 40%+. So if total number of endpoint chains
// is large enough, we simply drop those comments.
if proxier.endpointChainsNumber > endpointChainsNumberThreshold {
return
return args

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment above suggests that not returning the args was an explicit decision. I'm not sure that re-adding them is the right choice.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need return args here, otherwise on L1187 in this file will replace args by nil - see #81886 (comment).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fixed in #81563

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we wait for that PR to merge?

-A KUBE-SVC-3WUAALNGPYZZAWAD -j
-A -s 10.0.1.3/32 -j KUBE-MARK-MASQ
-A -m -p -j DNAT --to-destination 10.0.1.3:80
-A KUBE-SVC-3WUAALNGPYZZAWAD -m comment --comment ns1/svc1: -m statistic --mode random --probability 0.33333 -j

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As mentioned before, it makes sense that they comment sections indeed bloat the output.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment in the code there says "So if total number of endpoint chains is large enough, we simply drop those comments" and this small test doesn't exceed the threshold for not adding comments.

The code for adding comments was broken though, as described in #81886 (comment).

@@ -290,7 +290,7 @@ func (udp *udpProxySocket) proxyClient(cliAddr net.Addr, svrConn net.Conn, activ
klog.Errorf("SetDeadline failed: %v", err)
break
}
n, err = udp.WriteTo(buffer[0:n], cliAddr)
_, err = udp.WriteTo(buffer[0:n], cliAddr)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we ignoring this output? Is the linter complaining that it is not used?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, from the commit message:

pkg/proxy/userspace/proxysocket.go:293:3: this value of n is never used (SA4006)

@@ -99,26 +97,6 @@ type Proxier struct {
// assert Proxier is a proxy.Provider
var _ proxy.Provider = &Proxier{}

// A key for the portMap. The ip has to be a string because slices can't be map

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these pieces removed because they are not used?

Copy link
Contributor Author

@praseodym praseodym Sep 25, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, from the commit message:

pkg/proxy/winuserspace/proxier.go:88:2: field portMapMutex is unused (U1000)
pkg/proxy/winuserspace/proxier.go:112:2: field owner is unused (U1000)
pkg/proxy/winuserspace/proxier.go:113:2: field socket is unused (U1000)

(exact line numbers are different due to rebase / other changes)

@@ -1184,7 +1184,7 @@ func (proxier *Proxier) syncProxyRules() {
args = append(args[:0],
"-A", string(svcChain),
)
proxier.appendServiceCommentLocked(args, svcNameString)
args = proxier.appendServiceCommentLocked(args, svcNameString)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change means that the return value of appendServiceCommentLocked was previously not used, so comments were never added. PR #81563 was also opened to address this, but because this was also caught by staticcheck I have also fixed it in this PR.

@danwinship
Copy link
Contributor

/assign @thockin
/unassign @lavalamp

@k8s-ci-robot k8s-ci-robot assigned thockin and unassigned lavalamp Dec 12, 2019
@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Dec 12, 2019
@praseodym
Copy link
Contributor Author

Rebased and updated to fix some new staticcheck failures (see PR description or commit message for a complete list).

@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Dec 13, 2019
Copy link
Member

@thockin thockin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 comment for fixup

pkg/proxy/healthcheck/proxier_health.go Outdated Show resolved Hide resolved
// Not printing these comments, can reduce size of iptables (in case of large
// number of endpoints) even by 40%+. So if total number of endpoint chains
// is large enough, we simply drop those comments.
if proxier.endpointChainsNumber > endpointChainsNumberThreshold {
return
return args
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fixed in #81563

Errors from staticcheck:
pkg/proxy/healthcheck/proxier_health.go:55:2: field port is unused (U1000)
pkg/proxy/healthcheck/proxier_health.go:162:20: printf-style function with dynamic format string and no further arguments should use print-style function instead (SA1006)
pkg/proxy/healthcheck/service_health.go:166:20: printf-style function with dynamic format string and no further arguments should use print-style function instead (SA1006)
pkg/proxy/iptables/proxier.go:737:2: this value of args is never used (SA4006)
pkg/proxy/iptables/proxier.go:737:15: this result of append is never used, except maybe in other appends (SA4010)
pkg/proxy/iptables/proxier.go:1287:28: this result of append is never used, except maybe in other appends (SA4010)
pkg/proxy/userspace/proxysocket.go:293:3: this value of n is never used (SA4006)
pkg/proxy/winkernel/metrics.go:74:6: func sinceInMicroseconds is unused (U1000)
pkg/proxy/winkernel/metrics.go:79:6: func sinceInSeconds is unused (U1000)
pkg/proxy/winuserspace/proxier.go:94:2: field portMapMutex is unused (U1000)
pkg/proxy/winuserspace/proxier.go:118:2: field owner is unused (U1000)
pkg/proxy/winuserspace/proxier.go:119:2: field socket is unused (U1000)
pkg/proxy/winuserspace/proxysocket.go:620:4: this value of n is never used (SA4006)
@thockin
Copy link
Member

thockin commented Dec 23, 2019

Thanks!

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Dec 23, 2019
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: praseodym, thockin

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Dec 23, 2019
@praseodym
Copy link
Contributor Author

/retest

2 similar comments
@thockin
Copy link
Member

thockin commented Dec 23, 2019

/retest

@thockin
Copy link
Member

thockin commented Dec 23, 2019

/retest

@k8s-ci-robot k8s-ci-robot merged commit d758fc3 into kubernetes:master Dec 24, 2019
@k8s-ci-robot k8s-ci-robot added this to the v1.18 milestone Dec 24, 2019
@praseodym praseodym deleted the fix-staticcheck-pkg/proxy branch December 24, 2019 06:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. area/ipvs cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. lgtm "Looks good to me", indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. priority/important-longterm Important over the long term, but may not be staffed and/or may need multiple releases to complete. release-note-none Denotes a PR that doesn't merit a release note. sig/network Categorizes an issue or PR as relevant to SIG Network. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants